package cn.edu.zjicm.wordsnet_d.data;

import java.util.List;

public class BoardList {
	List<BoardItem> boardList;
	boolean myDataOnBoard;
	int myRank;

	public BoardList(List<BoardItem> boardList, boolean myDataOnBoard,
			int myRank) {
		super();
		this.boardList = boardList;
		this.myDataOnBoard = myDataOnBoard;
		this.myRank = myRank;
	}

	public List<BoardItem> getBoardList() {
		return boardList;
	}

	public void setBoardList(List<BoardItem> boardList) {
		this.boardList = boardList;
	}

	public boolean isMyDataOnBoard() {
		return myDataOnBoard;
	}

	public void setMyDataOnBoard(boolean myDataOnBoard) {
		this.myDataOnBoard = myDataOnBoard;
	}

	public int getMyRank() {
		return myRank;
	}

	public void setMyRank(int myRank) {
		this.myRank = myRank;
	}

	// 筛选出前3名，和本人前后5名的数据
	public void filter(){
		if(!myDataOnBoard){	//如果本人没上榜，只显示前三
			boardList = boardList.subList(0, 3 <= boardList.size() ? 3 : boardList.size());			
		} else {
			for(int i = boardList.size() - 1; i > 0; i--){
	            if(!isTop3orNear10(boardList.get(i).getRank()))
	            	boardList.remove(i);
	        }
		}
	}
	
	boolean isTop3orNear10(int rank) {
		if(rank >= 1 && rank <= 3)
			return true;
		if(rank >= myRank - 5 && rank <= myRank + 5)
			return true;
		return false;
	}
}